package 力扣;

import java.util.Stack;

/**
 * @author yyq
 * @create 2022-03-30 9:50
 */
public class leetcode1047 {
    public static void main(String[] args) {
        System.out.println(removeDuplicates("abaa"));
    }
    public static String removeDuplicates(String s) {
        Stack<Character> stack=new Stack<>();
        char[] chars = s.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            if(stack.size()==0) {
                stack.push(chars[i]);
                continue;
            }
            Character peek = stack.peek();
            if(peek == chars[i])
                stack.pop();
            else
                stack.push(chars[i]);
        }
        char[] cha=new char[stack.size()];
        for (int i = cha.length-1; i >=0; i--) {
            cha[i]=stack.pop();
        }

        return String.valueOf(cha);
    }
}
